var e = require;
var t = module;
cc.Class({
    extends: cc.Component,
    properties: {},
    onLoad: function onLoad() {
        if (
            ((this.angle = 2),
            (this.jiaodu = 180),
            (this.hudu = (this.jiaodu * Math.PI) / 180),
            (this.jiaodu = (this.hudu / Math.PI) * 180),
            (this.angle = (2 * this.jiaodu) / 360),
            (this.wainode = this.node.getChildByName("Wai")),
            (this.neinode = this.wainode.getChildByName("Nei")),
            (this.posCenter = cc.v2(0, 0)),
            null != this.wainode)
        ) {
            var e = this.wainode.getPosition();
            (this.posCenter = this.node.convertToWorldSpaceAR(e)), console.log(this.posCenter);
        }
        (this.radius = (this.wainode.width / 2 + this.wainode.height / 2) / 2),
            (this.posTouch = cc.v2(this.posCenter.x, this.posCenter.y)),
            (this.touchStart = !1),
            (this.spdMax = 300),
            (this.spd = 0),
            (this.dirSpdX = 0),
            (this.dirSpdY = 0),
            (this.spdPercent = 0),
            (this.thudu = 0),
            (this.sendedthudu = -10);
    },
    start: function start() {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this),
            this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this),
            this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEnd, this),
            this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this);
    },
    onTouchStart: function onTouchStart(e) {
        this.touchStart = !0;
        var t = e.getTouches();
        for (var o in t) {
            var n = t[o].getLocation();
            (this.posTouch.x = n.x), (this.posTouch.y = n.y);
            break;
        }
    },
    onTouchMove: function onTouchMove(e) {
        if (this.touchStart) {
            var t = e.getTouches();
            for (var o in t) {
                var n = t[o].getLocation();
                (this.posTouch.x = n.x), (this.posTouch.y = n.y);
                break;
            }
        }
    },
    onTouchEnd: function onTouchEnd() {
        (this.touchStart = !1), (this.posTouch = cc.v2(this.posCenter.x, this.posCenter.y));
    },
    onTouchCancel: function onTouchCancel(e) {
        this.onTouchEnd(e);
    },
    setNeiPos: function setNeiPos(e) {
        var t = null,
            o = e.sub(this.posCenter);
        o.mag() > this.radius
            ? ((o = o.normalize().mul(this.radius).add(this.posCenter)), (t = this.wainode.convertToNodeSpaceAR(o)))
            : (t = this.wainode.convertToNodeSpaceAR(e)),
            this.neinode.setPosition(t),
            (this.spdPercent = o.mag() / this.radius),
            this.spdPercent > 1 && (this.spdPercent = 1),
            (this.spd = this.spdMax * this.spdPercent),
            (this.dirSpdX = Math.cos(this.jiaodu) * this.spd);
    },
    setHuDuChangeListener: function setHuDuChangeListener(e) {
        this.huDuChangeListener = e;
    },
    update: function update() {
        var e = null,
            t = this.posTouch.sub(this.posCenter);
        t.mag() > this.radius
            ? ((t = t.normalize().mul(this.radius).add(this.posCenter)), (e = this.wainode.convertToNodeSpaceAR(t)))
            : (e = this.wainode.convertToNodeSpaceAR(this.posTouch)),
            this.neinode.setPosition(e);
        var o = this.posTouch.x - this.posCenter.x,
            n = this.posTouch.y - this.posCenter.y;
        this.posTouch.x != this.posCenter.x || this.posTouch.y != this.posCenter.y
            ? ((this.spdPercent = t.mag() / this.radius),
              this.spdPercent > 1 && (this.spdPercent = 1),
              (this.thudu = Math.atan2(n, o)))
            : (this.thudu = 0),
            this.hudu != this.thudu &&
                (this.huDuChangeListener && this.huDuChangeListener(this.thudu, this.hudu, o, n),
                (this.hudu = this.thudu));
    },
    resultDirData: function resultDirData(e, t) {
        if (t) this.thudu = t.thudu;
        else if (this.posTouch.x != this.posCenter.x || this.posTouch.y != this.posCenter.y) {
            (this.spdPercent = vecTouch.mag() / this.radius), this.spdPercent > 1 && (this.spdPercent = 1);
            var o = this.posTouch.x - this.posCenter.x,
                n = this.posTouch.y - this.posCenter.y;
            this.thudu = Math.atan2(n, o);
        }
    }
});
